package de.logicline.cvss.vo;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;

public class CVSSearchEntry {

	private String author;
	private Date date;
	private String comment;
	private String originalComment;
	private List files = new ArrayList();
	private List filePaths = new ArrayList();
	String filesToString = null;
	private IProject project;
	
	/** CVSSearchFiles */
	private List resources = new ArrayList();
	
	/**	 CVSLogFile.*/
	private List cvsLogFiles; 
	
	public CVSSearchEntry(String auth, String cmt, String origCmt, Date dte, IProject proj) {
		this.author = auth;
		this.comment = cmt;
		this.date = dte;
		this.project = proj;
		this.originalComment = origCmt;
	}

	public String getAuthor() {
		return author;
	}

	public String getComment() {
		return comment;
	}
	public String getOriginalComment() {
		return originalComment;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	public List getFiles() {
		return files;
	}
	public String getFilesAsString() {

	    IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
	    boolean fullpath = store.getBoolean("fullpath");
	    List display = null;
	   
	    if (fullpath)
	        display = filePaths;
	    else
	        display = files;
	    
	    if (this.filesToString == null) {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			for (int cc = 0; cc < display.size(); cc++) {
				pw.println(display.get(cc));
			}
			this.filesToString = sw.toString();
		}
		return this.filesToString;
	}

	public IProject getProject() {
		return project;
	}

	public void addFilePaths(String filePath) {
	    filePaths.add(filePath);
	}
	
	public List getFilePaths() {
		return filePaths;
	}
	
	public void addFiles(String file) {
		files.add(file);
	}
	
	public void addResource(IResource res) {
		resources.add(res);
	}
	
	public List getResources() {
		return resources;
	}
}
